/**********************************************************************************************************************
 *
 * Project:    mGameEngine
 * File:       soundsource.cpp
 * Author:     karooolek
 * Created on: 2009-03-24
 *
 **********************************************************************************************************************/

#include "soundsource.h"

namespace mGameEngine
{
namespace Audio
{

SoundSource::SoundSource() :
    _source(0), _sound(NULL),
    _play(false), _gain(1.0f), _loop(-1)
{
    alGenSources(1, &_source);
}


SoundSource::SoundSource(Sound *sound, uint loop) :
    _source(0), _sound(sound),
    _play(false), _gain(1.0f), _loop(loop)
{
    alGenSources(1, &_source);
    play();
}

SoundSource::~SoundSource()
{
    alDeleteSources(1, &_source);
}

void SoundSource::play()
{
    // temporary
    if(_sound)
    {
        alSourcei(_source, AL_BUFFER, _sound->buffer);
    }

    _play = true;

    if(_loop == -1)
    {
        alSourcei(_source, AL_LOOPING, AL_TRUE);
    }
    alSourcePlay(_source);

}

void SoundSource::pause()
{
    _play = false;

    alSourcePause(_source);
}

void SoundSource::stop()
{
    _play = false;

    alSourceStop(_source);
}

float SoundSource::getOffset() const
{
    // TODO
    return 0.0f;
}

void SoundSource::setOffset(float offset)
{
    // TODO
}


}
}

